<?php
if (!defined("_INDEX")) { header("Location: /"); die; }

$comment_id = $route->getByNum(5);

$comment = $db->getRow("select `C`.*,`R`.`user_id` from `comments` as `C`,`reports` as `R` where `C`.`comment_id` = '".$comment_id."' and `C`.`report_id` = `R`.`report_id` limit 1");

if (!$comment || $comment['user_id'] != $user->getUserId())
	goToPage("/coordinator/reports/look/comments");

if ($route->POST('type') == "post")
{
	$friend = UV::readMQ($route->POST('friend'));
	$link = UV::readMQ($route->POST('link'));
	$comment = UV::readMQ($route->POST('comment'));
	$ucomment = UV::readMQ($route->POST('ucomment'));
	
	$report = $db->sendQuery("update `comments` set `friend_id`='$friend',`link`='$link',`comment`='$comment',`ucomment`='$ucomment' where `comment_id` = '$comment_id' limit 1");
	
	require_once COORDINATOR.DS."head.php";
	if (!$report)
		echo "Ошибка! Проверьте введенные данные<br />";
	else
		goToPage("/coordinator/reports/look/comments");
}
else
{
	require_once COORDINATOR.DS."head.php";
	?>
	<script type='text/javascript'>
	$(document).ready(function(){
		$("#editForm").submit(function(){
			return confirm("Редактировать отчет?");
		});
	})
	</script>
	<form method="POST" id='editForm'>
		<input type='hidden' name='type' value='post' />
		<table cellpadding='0' cellspacing='5' style='width:600px;' border='0'>
			<tr>
				<td width="200px"><label for="friend">Пользователь</label></td>
				<td width="500px"><input type='text' name='friend' id='friend' value='<?php echo $comment['friend_id']; ?>' /></td>
			</tr>
			<tr>
				<td colspan='2' class='hint'>Ссылка на страницу пользователя (например: <span class='important'>http://my.mail.ru/mail/user/</span>)</td>
			</tr>
			<tr>
				<td><label for="link">Ссылка на статью/комментарий</label></td>
				<td><input type='text' name='link' id='link' value='<?php echo $comment['link']; ?>' /></td>
			</tr>
			<tr valign="top">
				<td><label for="comment">Комментарий</label></td>
				<td><textarea name='comment' id='comment' rows='5' style="width:100%"><?php echo $comment['comment']; ?></textarea></td>
			</tr>
			<tr>
				<td valign='top'><label for="ucomment">Ваш комментарий</label></td>
				<td><textarea name='ucomment' id='ucomment' style='width:100%' rows='5'><?php echo $comment['ucomment']; ?></textarea></td>
			</tr>
			<tr>
				<td colspan='4' align="right"><input type='submit' value="Редактировать" style='width:200px;height:35px' /></td>
			</tr>
		</table>
	</form><?php
}

require_once COORDINATOR.DS."footer.php";
?>